package com.chapter09;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.bdqn.util.JDBCUtils;
import com.chapter08.Test04_druid;
import org.apache.commons.dbutils.QueryRunner;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Test01_QueryRunner {
    public static void main(String[] args) throws Exception {
        // todo 1、创建数据源
        Properties properties = new Properties();
        InputStream inputStream = Test04_druid.class.getClassLoader()
                .getResourceAsStream("druid.properties");
        properties.load(inputStream);
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);

        // todo 2、创建QueryRunner对象
        QueryRunner queryRunner = new QueryRunner(dataSource);

        // todo 3、增删改、查

        // 添加：修改和删除，一样
//        String sql = "INSERT INTO grade(`GradeId`,`GradeName`) VALUES(?,?);";
//        int i = queryRunner.update(sql, "300", "300");
//        if (i > 0) {
//            System.out.println("成功");
//        }




    }
}
